<template>
  <div class="home-container">
    <!-- Snowflake elements -->
    <div v-for="n in 50" :key="n" class="snowflake">*</div>

    <div class="top-bar">
      <div class="placeholder"></div>
      <div class="auth-status">
        <template v-if="isLoggedIn">
          <div class="user-avatar" @click="goToProfile">
             <img src="../../public/user-icon.svg" alt="User Avatar" />
          </div>
          <el-button type="text" @click="handleLogout">退出</el-button>
        </template>
        <template v-else>
          <el-button type="text" @click="router.push('/login')">登录</el-button>
        </template>
      </div>
    </div>
    <h1 class="app-title">AI 应用中心</h1>
    <p class="app-subtitle">/ 探索 AI 的无限可能 /</p>
    <div class="app-grid">
      <el-card class="app-card" @click="router.push('/love-app')">
        <div class="card-icon">
          <img src="../../public/heart-icon.svg" alt="Love App Icon" />
        </div>
        <div class="card-content">
          <h2>AI 恋爱大师</h2>
          <p>智能情感顾问，帮你解答恋爱烦恼</p>
        </div>
        <el-button type="primary" class="enter-button">立即体验 →</el-button>
      </el-card>
      <el-card class="app-card" @click="router.push('/manus-app')">
         <div class="card-icon">
           <img src="../../public/robot-icon.svg" alt="AI App Icon" />
        </div>
        <div class="card-content">
          <h2>AI 超级智能体</h2>
          <p>全能型 AI 助手，解决各类专业问题</p>
        </div>
        <el-button type="primary" class="enter-button">立即体验 →</el-button>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import {useRouter} from "vue-router";
import { isLoggedIn, logout } from '../state/auth';

const router = useRouter();

const handleLogout = () => {
  logout();
  router.push('/login');
};

const goToProfile = () => {
  console.log('Go to user profile');
  router.push('/profile');
};

</script>

<style scoped>
/* Add animation keyframes */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Snowflake styles and animation */
.snowflake {
  position: fixed;
  top: -10px; /* Start above the viewport */
  z-index: 9999; /* Ensure snowflakes are on top */
  pointer-events: none; /* Allow clicking through snowflakes */
  color: #ffffff; /* Snowflake color */
  font-size: 14px; /* Snowflake size */
  animation: snowfall linear infinite;
}

/* Define snowfall animation */
@keyframes snowfall {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(0, 100vh, 0);
  }
}

/* Randomize snowflake properties using nth-child */
.snowflake:nth-child(odd) {
  left: 5%;
  animation-duration: 10s;
  animation-delay: 0.5s;
}

.snowflake:nth-child(even) {
  left: 15%;
  animation-duration: 12s;
  animation-delay: 1s;
}

.snowflake:nth-child(3n) {
  left: 25%;
  animation-duration: 15s;
  animation-delay: 2s;
}

.snowflake:nth-child(4n) {
  left: 35%;
  animation-duration: 9s;
  animation-delay: 1.5s;
}

.snowflake:nth-child(5n) {
  left: 45%;
  animation-duration: 13s;
  animation-delay: 3s;
}

.snowflake:nth-child(odd):nth-child(3n) {
    left: 55%;
    animation-duration: 11s;
    animation-delay: 2.5s;
}

.snowflake:nth-child(even):nth-child(4n) {
    left: 65%;
    animation-duration: 14s;
    animation-delay: 4s;
}

.snowflake:nth-child(7n) {
    left: 75%;
    animation-duration: 10s;
    animation-delay: 1s;
}

.snowflake:nth-child(8n) {
    left: 85%;
    animation-duration: 16s;
    animation-delay: 3.5s;
}

.snowflake:nth-child(9n) {
    left: 95%;
    animation-duration: 12s;
    animation-delay: 2s;
}

.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 40px 20px;
  background-color: #1a1a2e;
  color: #ffffff;
  /* Apply the animation */
  animation: fadeInUp 0.8s ease-out forwards;
}

.top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.placeholder {
    width: 100px;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9em;
}

.auth-status span {
    color: #ffffff;
}

.auth-status .el-button {
  color: #ffffff;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-title {
  font-size: 3em;
  color: #66b1ff;
  text-shadow: 0 0 10px #66b1ff;
  text-align: center;
  flex-grow: 0.2;
}

.app-subtitle {
  font-size: 1.2em;
  color: #b3b3b3;
  margin-bottom: 60px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 40px;
  max-width: 900px;
  width: 100%;
}

.app-card {
  background-color: #2a2a40;
  border: 1px solid #404060;
  border-radius: 12px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

.app-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
}

.card-icon {
  width: auto;
  height: 80px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-content h2 {
  font-size: 1.8em;
  margin-bottom: 10px;
  color: #66b1ff;
}

.card-content p {
  color: #b3b3b3;
  margin-bottom: 20px;
  flex-grow: 1;
}

.enter-button {
  margin-top: auto;
}

@media (max-width: 768px) {
  .home-container {
      padding: 20px 10px;
  }

  .top-bar {
    flex-direction: column-reverse;
    align-items: center;
    margin-bottom: 10px;
  }

  .placeholder {
      display: none;
  }

  .auth-status {
    width: 100%;
    justify-content: center;
    margin-bottom: 10px;
  }

  .app-title {
    font-size: 2em;
    margin-bottom: 0;
  }

  .app-subtitle {
    font-size: 1em;
    margin-bottom: 30px;
  }

  .app-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .app-card {
    padding: 15px;
  }

  .card-icon {
      height: 60px;
      margin-bottom: 15px;
  }

  .card-content h2 {
      font-size: 1.5em;
  }

  .card-content p {
      font-size: 0.9em;
      margin-bottom: 15px;
  }
}
</style> 